package cn.com.io.day20151210;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

/**
 * 字符输入、输出流
 */
public class StringNodeTest {
    public static void main(String[] args) throws IOException {
        String word = "Spring\n"+"Mybatis\n"+"Hibernate\n";
        StringReader reader = new StringReader(word);
        char[] buf = new char[32];
        int hasRead = 0;
        while((hasRead = reader.read(buf)) > 0){
            System.out.println(new String(buf,0,hasRead));
        }

        //创建StringWriter时实际上以一个StringBuffer作为输出节点
        StringWriter writer = new StringWriter(20);//指定StringBuffer的初始长度
        writer.write("Spring\n");
        writer.write("Mybatis\n");
        writer.write("Hibernate\n");
        System.out.println(writer.toString());//返回字符串节点的内容
    }
}
